package com.ruoyi.web.sso.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.web.sso.common.util.AssertUtil;
import com.ruoyi.web.sso.common.util.UuidUtil;
import com.ruoyi.web.sso.domain.vo.AddPlatform;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.sso.mapper.PlatformMapper;
import com.ruoyi.web.sso.domain.Platform;
import com.ruoyi.web.sso.service.IPlatformService;
import com.ruoyi.common.core.text.Convert;

/**
 * 系统Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-10-28
 */
@Service
public class PlatformServiceImpl implements IPlatformService 
{
    @Autowired
    private PlatformMapper platformMapper;

    /**
     * 查询系统
     * 
     * @param platformId 系统主键
     * @return 系统
     */
    @Override
    public Platform selectPlatformByPlatformId(String platformId)
    {
        return platformMapper.selectPlatformByPlatformId(platformId);
    }

    /**
     * 查询系统列表
     * 
     * @param platform 系统
     * @return 系统
     */
    @Override
    public List<Platform> selectPlatformList(Platform platform)
    {
        return platformMapper.selectPlatformList(platform);
    }

    /**
     * 新增系统
     * 
     * @param platform 系统
     * @return 结果
     */
    @Override
    public int insertPlatform(Platform platform)
    {
        platform.setCreateTime(DateUtils.getNowDate());
        return platformMapper.insertPlatform(platform);
    }

    /**
     * 修改系统
     * 
     * @param platform 系统
     * @return 结果
     */
    @Override
    public int updatePlatform(Platform platform)
    {
        platform.setUpdateTime(DateUtils.getNowDate());
        return platformMapper.updatePlatform(platform);
    }

    /**
     * 批量删除系统
     * 
     * @param platformIds 需要删除的系统主键
     * @return 结果
     */
    @Override
    public int deletePlatformByPlatformIds(String platformIds)
    {
        return platformMapper.deletePlatformByPlatformIds(Convert.toStrArray(platformIds));
    }

    /**
     * 删除系统信息
     * 
     * @param platformId 系统主键
     * @return 结果
     */
    @Override
    public int deletePlatformByPlatformId(String platformId)
    {
        return platformMapper.deletePlatformByPlatformId(platformId);
    }

    @Override
    public AjaxResult add(AddPlatform addPlatform) {
        Platform platform  = platformMapper.getByName(addPlatform.getName());
        if (AssertUtil.isNotEmpty(platform)){
            return AjaxResult.error("名称已存在！");
        }
        platform = new Platform();
        BeanUtils.copyProperties(addPlatform , platform);
        platform.setPlatformId(UuidUtil.getUuid());
        platformMapper.insertPlatform(platform);
        return AjaxResult.success("添加成功！");
    }

    @Override
    public AjaxResult remove(String platformId) {
        Platform platform  = platformMapper.selectPlatformByPlatformId(platformId);
        if (AssertUtil.isEmpty(platform)){
            return AjaxResult.error("删除ID不存在！");
        }
        platform.setDeleted("1");
        platformMapper.updatePlatform(platform);
        return AjaxResult.success("删除成功！");
    }

    @Override
    public List<Platform> selectStaffPlatform(String staffId) {
        return platformMapper.selectStaffPlatform(staffId);
    }
}
